package com.livepan.business.controller;

import com.livepan.server.BaseController;
import com.livepan.server.error.BusinessException;
import com.livepan.server.response.CommonReturnType;
import com.livepan.server.service.SectionService;
import com.livepan.server.service.model.SectionModel;
import com.livepan.server.service.model.PageModel;
import com.livepan.server.service.model.SectionPageModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/section")
public class SectionController extends BaseController {

    public static final String BUSINESS_NAME="小节";

    private static final Logger LOG = LoggerFactory.getLogger(SectionController.class);

    @Autowired
    private SectionService sectionService;

    @ResponseBody
    @RequestMapping("/list")
    public CommonReturnType list(SectionPageModel sectionPageModel) {
        LOG.info("page:" + sectionPageModel.getPage());
        sectionService.list(sectionPageModel);
        return CommonReturnType.create(sectionPageModel);
    }

    @ResponseBody
    @RequestMapping("/save")
    public CommonReturnType saveSection(@RequestBody SectionModel sectionModel) throws Exception {
        sectionService.save(sectionModel);
        return CommonReturnType.create(sectionModel);
    }

    @ResponseBody
    @RequestMapping("/delete/{id}")
    public CommonReturnType delete(@PathVariable String id) {
        sectionService.delete(id);
        return CommonReturnType.create(null);
    }
}
